﻿using System;
using BestEasyCMS.Framework.Domain;
using NPoco;

namespace BestEasyCMS.Model.Security
{
    /// <summary>
    /// 后台用户实体
    /// </summary>
    [TableName("tb_Sec_Users")]
    [PrimaryKey("Id")]
    [Serializable]
    public class User : Entity<long>
    {
        /// <summary>
        /// 登录用户名
        /// </summary>
        public string LoginName { get; set; }
        /// <summary>
        /// 密码
        /// </summary>
        public string Password { get; set; }
        /// <summary>
        /// 角色ID
        /// </summary>
        public long RoleId { get; set; }
        /// <summary>
        /// 角色  --  类属性
        /// </summary>
        [ResultColumn]
        public virtual Role Role { get; set; }
        /// <summary>
        /// 真实姓名
        /// </summary>
        public string RealName { get; set; }
        /// <summary>
        /// 身份证号
        /// </summary>
        public string IdCard { get; set; }
        /// <summary>
        /// 电子邮箱
        /// </summary>
        public string Email { get; set; }
        /// <summary>
        /// QQ
        /// </summary>
        public string QQ { get; set; }
        /// <summary>
        /// 微信号
        /// </summary>
        public string WeChat { get; set; }
        /// <summary>
        /// 备注
        /// </summary>
        public string Remarks { get; set; }
        /// <summary>
        /// 最后登录时间
        /// </summary>
        public DateTime? LastLoginTime { get; set; }
        /// <summary>
        /// 最后登录Ip
        /// </summary>
        public string LastLoginIp { get; set; }
        /// <summary>
        /// 允许登录IP 多个逗号分割
        /// </summary>
        public string AllowLoginIps { get; set; }

        protected override void Verify()
        {
            if (LoginName == "")
                AddBrokenRule(new BusinessRule("LoginName", "登录名不能为空！"));
            if (RoleId <= 0)
                AddBrokenRule(new BusinessRule("RoleId", "用户角色不合法！"));
        }
    }
}

